//
//  UIButton.swift
//  WeiBoStudy
//
//  Created by luoerliu on 16/5/23.
//  Copyright © 2016年 刘文平. All rights reserved.
//

import UIKit
extension UIButton
{
//    创建便利构造函数
    convenience init(bkgImageName:String,imageName:String,title:String,titleColor:    UIColor = UIColor.lightGrayColor(),fontSize: CGFloat = 12)
    {
          // 先调用当前类的指定或便利构造函数创建对象,创建完对象后给对象设置参数
        self.init(type:UIButtonType.Custom)
        self.setBackgroundImage(UIImage(named: bkgImageName), forState: UIControlState.Normal)
        self.setBackgroundImage(UIImage(named: "\(bkgImageName)_highlighted"), forState: UIControlState.Highlighted)
        self.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        self.setTitle(title, forState: UIControlState.Normal)
        self.setTitleColor(titleColor, forState: UIControlState.Normal)
        self.titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
}
